<?php

Yii::import('common.models._base.BaseCategory');

class Category extends BaseCategory {

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function rules() {
        return array(
            array('name, status', 'required'),
            array('parent', 'safe'),
        );
    }

    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'parent' => array(self::BELONGS_TO, 'Category', 'parent', 'condition' => 't.parent <> 0'),
            'children' => array(self::HAS_MANY, 'Category', 'parent'),
                // here SkillCategory is model and parentcategory_id is filed name that will contain parent id
        );
    }

    public function getCategoryname($id) {
        if ($id == 0):
            $name = "No subcategory";
        else:
            $model = new Category;
            $mydata = $model->findByPk($id);
            $name = $mydata['name'];
        endif;
        return $name;
    }

}